package com.ruoyi.web.controller.cms;

import com.ruoyi.cms.domain.CmsContent;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cms.domain.CmsDjContent;
import com.ruoyi.cms.service.ICmsDjContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 党建Controller
 * 
 * @author hct
 * @date 2022-01-22
 */
@RestController
@RequestMapping("/cms/dj/content")
public class CmsDjContentController extends BaseController
{
    @Autowired
    private ICmsDjContentService cmsDjContentService;

    /**
     * 查询党建列表
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsDjContent cmsDjContent)
    {
        startPage();
        List<CmsDjContent> list = cmsDjContentService.selectCmsDjContentList(cmsDjContent);
        return getDataTable(list);
    }

    /**
     * 导出党建列表
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:export')")
    @Log(title = "党建", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsDjContent cmsDjContent)
    {
        List<CmsDjContent> list = cmsDjContentService.selectCmsDjContentList(cmsDjContent);
        ExcelUtil<CmsDjContent> util = new ExcelUtil<CmsDjContent>(CmsDjContent.class);
        util.exportExcel(response, list, "党建数据");
    }

    /**
     * 获取党建详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsDjContentService.selectCmsDjContentById(id));
    }

    /**
     * 新增党建
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:add')")
    @Log(title = "党建", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsDjContent cmsDjContent)
    {
        return toAjax(cmsDjContentService.insertCmsDjContent(cmsDjContent));
    }

    /**
     * 修改党建
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:edit')")
    @Log(title = "党建", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsDjContent cmsDjContent)
    {
        return toAjax(cmsDjContentService.updateCmsDjContent(cmsDjContent));
    }

    /**
     * 删除党建
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:remove')")
    @Log(title = "党建", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsDjContentService.deleteCmsDjContentByIds(ids));
    }

    /**
     * 上架下架信息
     */
    @PreAuthorize("@ss.hasPermi('cms:dj:changMarktable')")
    @Log(title = "园区信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changMarktable")
    public AjaxResult changMarktable(Long id,Integer markTable)
    {
        CmsDjContent cmsContent=new CmsDjContent();
        cmsContent.setId(id);
        cmsContent.setIsMarketable(markTable);
        return toAjax(cmsDjContentService.updateCmsDjContent(cmsContent));
    }

}
